import Vue from 'vue'
// import { getToken } from '@/utils/storage'
import VueRouter from 'vue-router'
import Login from '@/views/login'
import Register from '@/views/register'
import Detail from '@/views/detail'
import Layout from '@/views/layout'
import Search from '@/views/search'
import Sell from '@/views/sell'

import Like from '@/views/like'
import Article from '@/views/article'
import Collect from '@/views/collect'
import User from '@/views/user'
import City from '@/views/city'
import Map from '@/views/map'
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/login', component: Login },
    { path: '/register', component: Register },
    { path: '/city', component: City },
    { path: '/search', component: Search },
    { path: '/like', component: Like },
    { path: '/map', component: Map },
    {
      path: '/',
      component: Layout,
      redirect: '/article',
      children: [
        { path: '/detail', component: Detail },
        { path: '/article', component: Article },
        {
          path: '/user',
          component: User
        },
        { path: '/collect', component: Collect },
        { path: '/sell', component: Sell }
      ]
    }
  ]
})
// const whiteList = ['/login', '/', '/user']
// router.beforeEach((to, from, next) => {
//   const { token } = getToken()
//   console.log(to)
//   if (token) {
//     next()
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })
export default router
